# 模型，数据库相关的文件
# 模型 ==> 数据库
# 类   ==> 表这个结构
# 类的属性 ==> 表中的字段
# 单个对象 ==> 将要存入或者已经存入表中的一行数据
from .exts import db


# 用户信息
class Users(db.Model):
    __tablename__ = 'Users'
    user_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_name = db.Column(db.String(50), unique=True, nullable=False)
    user_number = db.Column(db.String(100), nullable=False)
    user_password = db.Column(db.String(100), nullable=False)
    user_fan = db.Column(db.Integer, default=0)
    user_attention = db.Column(db.Integer, default=0)

    def __init__(self, user_id, user_name, user_number, user_password, user_fan, user_attention):
        self.user_id = user_id
        self.user_name = user_name
        self.user_number = user_number
        self.user_password = user_password
        self.user_fan = user_fan
        self.user_attention = user_attention


# 管理员
class Manager(db.Model):
    __tablename__ = 'Manager'
    manager_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    id = db.Column(db.Integer, db.ForeignKey('Users.user_id'), nullable=False)  # 外键

    def __init__(self, manager_id, id):
        self.manager_id = manager_id
        self.id = id


# 关注&粉丝
class AttentionFan(db.Model):
    __tablename__ = 'AttentionFan'
    af_number = db.Column(db.Integer, primary_key=True, autoincrement=True)
    af_parent_id = db.Column(db.Integer, nullable=False)
    af_children_id = db.Column(db.Integer, nullable=False)

    def __init__(self, af_number, af_parent_id, af_children_id):
        self.af_number = af_number
        self.af_parent_id = af_parent_id
        self.af_children_id = af_children_id


# 产品信息
class Product(db.Model):
    __tablename__ = 'Product'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(100), nullable=False)
    type_id = db.Column(db.Integer, nullable=False, default=0)
    product_name = db.Column(db.String(100), nullable=False)
    details = db.Column(db.Text)
    picture = db.Column(db.Text)
    music_address = db.Column(db.Text)
    video_address = db.Column(db.Text)
    price = db.Column(db.Text)
    evalute = db.Column(db.Text)

    def __init__(self, id, type_name, type_id, product_name, details, picture, music_address, video_address, price, evalute):
        self.id = id
        self.type_name = type_name
        self.type_id = type_id
        self.product_name = product_name
        self.details = details
        self.picture = picture
        self.music_address = music_address
        self.video_address = video_address
        self.price = price
        self.evalute = evalute


# 评论区
class Comment(db.Model):
    __tablename__ = 'Comment'
    comment_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_comment = db.Column(db.Integer, nullable=False, default=0)
    comment_user = db.Column(db.Integer, nullable=False)
    comment_number = db.Column(db.Integer, nullable=False, default=0)
    comment_content = db.Column(db.Text)
    type_number = db.Column(db.Integer, nullable=False, default=1)
    comment_data = db.Column(db.String(100))
    comment_like = db.Column(db.Integer, default=0)

    def __init__(self, comment_id, type_comment, comment_user, comment_number, comment_content, type_number):
        self.comment_id = comment_id
        self.type_comment = type_comment
        self.comment_user = comment_user
        self.comment_number = comment_number
        self.comment_content = comment_content
        self.type_number = type_number


# 评论区关系
class CommentRelationship(db.Model):
    __tablename__ = 'CommentRelationship'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    source = db.Column(db.Integer, db.ForeignKey('Comment.comment_id'), autoincrement=True)
    rltp_parent = db.Column(db.Integer, nullable=False)
    rltp_children = db.Column(db.Integer, nullable=False)

    def __init__(self, id, source, rltp_parent, rltp_children):
        self.id = id
        self.source = source
        self.rltp_parent = rltp_parent
        self.rltp_children = rltp_children


# 评论区点赞
class CommentLike(db.Model):
    __tablename__ = 'CommentLike'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    source = db.Column(db.Integer, db.ForeignKey('Comment.comment_id'), autoincrement=True)
    like_parent = db.Column(db.Integer, nullable=False)
    like_children = db.Column(db.Integer, nullable=False)

    def __init__(self, id, source, like_parent, like_children):
        self.id = id
        self.source = source
        self.like_parent = like_parent
        self.like_children = like_children



# 模型Model： 类 hello world!!!
# 必须继承 db.Model
# db.Column: 表示字段
# db.Integer: 表示整数
# primary_key= True : 主键
# db.ForeignKey('表的名称.元素名称') : 设置成外键
# autoincrement = True ：自动递增
# db.String(30) ： 可变字符串长度为30
# unique= True ： 字符串唯一约束
# index = True ： 创建一个普通索引
# default=1 ；默认值为1
# sex = db.Column(db.Boolean,
#                 default= True)
# salary = db.Column(db.Float,
#                    default=100000,
#                    nullable=False)
# #nullable=False : 是否允许为空
